<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: "twj",
            age: 100,
            location: {
                province: "邵阳",
                city: "大连"
            },
            get city() {
                return this.location.city
            },
            set city(value) {
                return this.location.city = value
            },
            get uppername() {
                console.log("get")
                return this.name.substring(0, 1).toUpperCase() + this.name.substring(1)
            },
            set uppername(value) {
                //console.log("set", value)
                this.name = value
            }
        }
        let obj1 = {}
        //将obj中所有属性都复制给obj1，但是get/set并不会复制过去
        //Object.assign(obj1, obj)
        //不仅能复制所有属性，get/set也能复制
        Object.defineProperties(obj1, Object.getOwnPropertyDescriptors(obj))
    </script>
</body>

</html>